package com.zhuwhao.sample;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.TextView;

import com.zhuwhao.sample.utils.AppUtils;
import com.zhuwhao.sample.utils.DropDownMenuUtils;
import com.zhuwhao.sample.widget.DropDownMenu;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DropDownMenuActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @BindView(R.id.dropDownMenu)
    DropDownMenu dropDownMenu;

    @BindView(R.id.textContent)
    TextView textContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drop_down_menu);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        toolbar.setTitle(R.string.drop_down_menu);
        setSupportActionBar(toolbar);

        textContent.setText("啦啦啦啦啦啦啦");

        DropDownMenuUtils utils = new DropDownMenuUtils.Builder(this, dropDownMenu)
                .addTestView()
                .addFilterView()
                .setListener(new DropDownMenuUtils.OnClickListener() {
                    @Override
                    public void onClick(int tabPosition, String... tag) {
                        AppUtils.showToast(DropDownMenuActivity.this, tag[0] + " -- " + tabPosition);
                    }
                }).builder();
        dropDownMenu.setDropDownMenu(Arrays.asList("Tab1", "Tab2"), utils.getPopupViews());
    }

    @Override
    public void onBackPressed() {
        if (dropDownMenu.isVisible()) {
            dropDownMenu.close();
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
